 
import Foundation
import  Moya
 

 enum Api{
    case postLogin(name:String , pass:String )
    case getHome
  
 } 

 extension Api :TargetType{
    //模拟操作不理会
    var sampleData: Data {
        return "data".data(using: String.Encoding.utf8)!
    }
    var method: Moya.Method {
        switch self {
        case .getHome:
            return .get
        case .postLogin:
            return .post
        }
    }
 
    public var task: Moya.Task {
        var param:[String:Any] = [:]
        
        switch self {
        case let .postLogin(name ,pass):
            param["name"] = name
            param["pass"] = pass
        default:
            //不需要传参数的走这里
            return .requestPlain
        }
        return .requestParameters(parameters: param, encoding: URLEncoding.default)
   
    }
    
    //请求头设置
    public var headers: [String : String]? {
        return nil
    }

    //请实际求url
    var path: String {
        switch self {
        case .postLogin:
            return "auth/login"
        case .getHome:
            return "auth/home"
        }
    }
    
    //base URL
    var baseURL: URL {
        return URL.init(string:"https://feiyujava.applinzi.com/")!
    }
    
 }
